package myLock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyLock implements Runnable{
    Lock lock=new ReentrantLock();
    int ticket;
    @Override
    public void run() {
            while (true){
                lock.lock();
                ticket++;
                if (ticket>100){
                    lock.unlock();
                    break;
                }
                System.out.println(Thread.currentThread().getName() + "第" + ticket + "张票");
                lock.unlock();
            }

    }
}
